package ${pkg};

import java.util.List;
import java.util.Map;
import java.util.function.Function;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.blue.jdbc.Page;
import com.blue.validation.ValidationUtil;
import com.blue.validation.group.SaveModel;
import com.blue.validation.group.UpdateModel;

import ${modelPkg}.${clazz};
import ${servicePkg}.${clazz}Service;
import ${facadePkg}.${clazz}Facade;
import ${exceptionPkg}.${clazz}Exception;
import ${convertorPkg}.${clazz}Convertor;
import ${messagePkg}.${clazz}Request;
import ${messagePkg}.${clazz}Response;
<#if impList??>
<#list impList as vo>
import ${vo};
</#list>
</#if>

/**
 * ${name}接口实现类
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 ${.now?string("yyyy年MM月dd日")}
 */
@Component
public class ${clazz}Provider implements ${clazz}Facade
{
	@Resource
	private ${clazz}Service ${field}Service;
	
	public ${clazz}Provider()
	{
	}

	@Override
	public ${clazz}Response add(${clazz}Request request)
	{
		ValidationUtil.valid(request, SaveModel.class);
		${clazz} ${field} = ${clazz}Convertor.to${clazz}(request);
		${field} = ${field}Service.save(${field});
		${clazz}Response response = ${clazz}Convertor.toResponse(${field});
		return response;
	}

	@Override
	public ${clazz}Response update(${clazz}Request request)
	{
		ValidationUtil.valid(request, UpdateModel.class);
		${clazz} ${field} = ${clazz}Convertor.to${clazz}(request);
		${field} = ${field}Service.save(${field});
		${clazz}Response response = ${clazz}Convertor.toResponse(${field});
		return response;
	}

	@Override
	public ${clazz}Response get(Integer id)
	{
		if (id == null)
			throw new ${clazz}Exception("Id不能为空");
			
		${clazz} ${field} = ${field}Service.get(id);
		${clazz}Response response = ${clazz}Convertor.toResponse(${field});
		return response;
	}

	@Override
	public Page<${clazz}Response> listPage(${clazz}Request request, int start, int size)
	{
		${clazz} ${field} = ${clazz}Convertor.to${clazz}(request);
		Page<${clazz}> page = new Page<>(size);
		page.setCurPage(start);
		page = ${field}Service.list(${field}, page);
		Page<${clazz}Response> pageResponse = ${clazz}Convertor.toResponse(page);
		return pageResponse;
	}
	
}
